import wizard
import pooler
from tools.misc import UpdateableStr,UpdateableDict
import time
import operator
from osv import osv, fields
from osv.orm import intersect
import tools.sql
from tools import config
from tools.translate import _
from mx import DateTime

class wizard_orders_detail_sheet(wizard.interface):
    
    def _get_records(self, cr, uid, data, context={}):
        pool = pooler.get_pool(cr.dbname)
        prj_obj = pool.get('account.analytic.account')
        ids = []
        check=False
        try:
            prj_ids=data['ids']
            check=True
        except:
            prj_ids=data['id']
        if prj_ids:
            list_prjs=prj_obj.browse(cr,uid,prj_ids)
            for x in list_prjs:
                for ord in x.order_ids:
                    ids.append(ord.id)
        data['model']='purchase.order'
        if check:
            data['ids']=ids
        else:
            data['id']=ids
        #ids=data['ids']
        data['active_ids']=ids
        if ids:
            data['active_id']=ids[0]
            id=ids[0]            
        return {'ids' : ids ,'model':'purchase.order', 'title' : 'Orders Detail','_terp_model':'purchase.order',} 
        
    states = {
        'init': {
            'actions': [_get_records],
            'result': {
                'type': 'print',
                'name' : 'Order Details',
                'report': 'orders.detail',
                'rml' : 'account_analytic_summary/report/project_orders_detail.jrxml',
                'state': 'end'
                        },
                },
}
wizard_orders_detail_sheet('jreports.orders_detail_sheet.wizard')